package com.baijia.dao.impl;

import com.baijia.dao.DeleteStatus;
import com.baijia.dao.OrgCascadeAccountDao;
import com.baijia.dao.po.OrgCascadeAccount;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Repository;

import java.util.Date;

@Repository
public class OrgCascadeAccountDaoImpl extends CommonDaoImpl<OrgCascadeAccount, Long> implements OrgCascadeAccountDao {

    public OrgCascadeAccountDaoImpl() {
        super(OrgCascadeAccount.class);
    }

    @Override
    public OrgCascadeAccount findByUsername(String username) {
        try {
            return jdbcTemplate.queryForObject(selectSql + " where username=? and isdel=?",
                new BeanPropertyRowMapper<>(OrgCascadeAccount.class),
                new Object[] { username, DeleteStatus.NORMAL.getValue() });
        } catch (Exception e) {
            return null;
        }
    }

    private String selectSql =
        "select id,org_id,org_number,username,password,staffname,status,pc_auth,app_auth,create_time,last_login_time,isdel,update_time from yunying.org_cascade_account ";

    /*
     * (non-Javadoc)
     * 
     * @see com.baijia.dao.impl.CommonDaoImpl#selectSql()
     */
    @Override
    protected String selectSql() {
        return selectSql;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.baijia.dao.OrgCascadeAccountDao#updateLastLoginTime(java.util.Date)
     */
    @Override
    public void updateLastLoginTime(Long id, Date time) {
        jdbcTemplate.update("update yunying.org_cascade_account set last_login_time=? where id=?", time, id);
    }

    // @Override
    // public int updateMobileByOrgId(String mobile, Long cascadeOrgId) {
    // return jdbcTemplate.update(
    // "update yunying.org_cascade_account set mobile=?, mobile_verify_status=1 where org_id=?", new Object[] {
    // mobile, cascadeOrgId });
    // }
}
